package search;

public class BiSearch {
	private static int[] orderArray = new int[]{1,6,12,29,34,55,87,96,124,156};

	public static int search(int key){
		int mid=0;
		int low=0;
		int high=orderArray.length-1;
		while(low<high){
			double item1 = (high-low)*(key-orderArray[low]);
			double item2 = (orderArray[high]-orderArray[low]);
			mid=(int)(low+item1/item2);
			if(mid<orderArray.length-1){
				if(key<orderArray[mid]){
					high=mid-1;
				}else if(key>orderArray[mid]){
					low=mid+1;
				}else{
					return mid;
				}
			}else{
				return -1;
			}
		}
		return -1;
	}
	
	public static void main(String[] args) throws Exception{
		System.out.println("position:"+search(12));
		System.out.println("position:"+search(380));
	}
}
